package com.beauty.inventory.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.extern.slf4j.Slf4j;

@Configuration
@Slf4j
public class RedissonConfig {

    @Value("${spring.data.redis.host:localhost}")
    private String host;
    
    @Value("${spring.data.redis.port:6379}")
    private String port;
    
    @Value("${spring.data.redis.password:}")
    private String password;
    
    @Value("${spring.data.redis.database:0}")
    private int database;
    
    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        String redisAddress = "redis://" + host + ":" + port;
        
        log.info("【Redisson】正在配置Redisson客户端，连接地址：{}，数据库：{}", redisAddress, database);
        
        config.useSingleServer()
                .setAddress(redisAddress)
                .setDatabase(database);
        
        if (password != null && !password.isEmpty()) {
            log.info("【Redisson】设置Redis密码");
            config.useSingleServer().setPassword(password);
        }
        
        log.info("【Redisson】Redisson客户端配置完成");
        return Redisson.create(config);
    }
} 